package com.itheima;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

public class ArrayListDemo {
    public static void main(String[] args){
        ArrayList<String>list = new  ArrayList<String>();
        list.add("zhangsan");
        list.add(0,"lisi");

        String s = list.get(1);
        System.out.println(s);

        list.set(0,"wangwu");
        list.remove(1);

        list.add("zhaoliu");
        list.add("zhaoliu");
        list.add("zhaoliu");
        list.add("zhaoliu");
        list.add("zhaoliu");

        System.out.println(list);
        System.out.println("-----------------------集合的遍历方法----------------------");
        for (int i = 0;i <list.size();i++){
            String obj = list.get(i);
            System.out.println(obj);
        }
        System.out.println("-----------------------集合的遍历方法2----------------------");
        for (String obj:list) {
            System.out.println(obj);
        }
        System.out.println("-----------------------集合的遍历方法3----------------------");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
        //Lambda表达式
        System.out.println("-----------------------集合的遍历方法4----------------------");
//        Consumer<String> consumer = ;
//        list.forEach(str-> System.out.println(str));
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        list.forEach( name-> System.out.println(name));

        list.forEach(System.out::println);
    }
}
